package com.oracle.oa.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.oracle.oa.util.PageBean;

public class SplitPageChuqin extends ActionSupport implements SessionAware {

	//给出勤率进行分页
	
	Map<String, Object> session;
	
	private String page;
	private int type;
	private String myresult;

	
	
	
	@SuppressWarnings("null")
	@Override
	public String execute() throws Exception {
		PageBean pb=new PageBean();
		
		List pagelist=new ArrayList();
		
		int currentPage=1;
		//设置当前页
		
		//判断要分页的集合
		if(Integer.parseInt(session.get("type").toString())==1 || type==1){
			List lvlist=(List) session.get("lvlist");
			pb.setAllRow(lvlist.size());
			if(page!=null){
				currentPage=Integer.parseInt(page);
				if(currentPage<1){
					currentPage=1;
				}
				if(currentPage>pb.getTotalPage()){
					currentPage=pb.getTotalPage();
				}
			}
			if(lvlist!=null && lvlist.size()>0){
				for(int i=0;i<4;i++){
					pagelist.add(lvlist.get((pb.getPageSize()*(currentPage-1))+i));
					if(lvlist.get((pb.getPageSize()*(currentPage-1))+i).equals(lvlist.get(lvlist.size()-1))){
						break;
					}
				}
				myresult="success";
			}else{
				myresult="no";
			}
			
		}else if(Integer.parseInt(session.get("type").toString())==2 || type==2){
			List slmslist=(List) session.get("slmslist");
			pb.setAllRow(slmslist.size());
			if(page!=null){
				currentPage=Integer.parseInt(page);
				if(currentPage<1){
					currentPage=1;
				}
				if(currentPage>pb.getTotalPage()){
					currentPage=pb.getTotalPage();
				}
			}
			if(slmslist!=null && slmslist.size()>0){
			for(int i=0;i<4;i++){
				pagelist.add(slmslist.get((pb.getPageSize()*(currentPage-1))+i));
				if(slmslist.get((pb.getPageSize()*(currentPage-1))+i).equals(slmslist.get(slmslist.size()-1))){
					break;
				}
			}
			myresult="error1";
			}else{
				myresult="no";
			}
		}
		
		pb.setList(pagelist);
		pb.setCurrentPage(currentPage);
		
		session.put("pb", pb);
		return myresult;
	}

	public void setSession(Map<String, Object> arg0) {
		this.session=arg0;
	}



	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getMyresult() {
		return myresult;
	}

	public void setMyresult(String myresult) {
		this.myresult = myresult;
	}

	
}
